Page({

  /**
   * 页面的初始数据
   */
  data: {
    scrollTop: 0,
    swiperList: [{
        title: "知识库",
        img: "/img/knowledge.png",
        url: '/pages/knowledge/knowledge'
      },
      {
        title: "人力资源管理",
        img: "/img/manpower.png",
        url: '/pages/manpower_resource/manpower_resource'
      },
      {
        title: "运营管理",
        img: "/img/operation.png",
        url: '/pages/operations/operations'
      },
      {
        title: "可疑件登记",
        img: "/img/dubious.png",
        url: '/pages/suspicious/suspicious'
      },
      {
        title: "费用管理",
        img: "/img/free.png",
        url: '/pages/expenseManagement/expenseManagement'
      },
      {
        title: "协议客户管理",
        img: "/img/agreement_customer.png",
        url: '/pages/agreementCustomer/agreementCustomer'
      },
      {
        title: "反馈核查",
        img: "/img/dubious.png",
        url: '/pages/feedbackVerif/feedbackVerif'
      }
    ],
    show: false,
    toady_cnt: 0,                       // 今日运单数
    week_cnt: 0,                        // 今日运单数
    mouth_cnt: 0,                       // 今日运单数
    company_name: "",                    // 公司名称
    legal_person: "",
    company_type:0
  },
  toRoute(e) {
    console.log('val', e)
    let { url_path } = e.currentTarget.dataset;
    wx.navigateTo({
      url: url_path,
    })
  
  },
  tobusiness() {
    wx.navigateTo({
      url: '/pages/business_data/business_data',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  // 获取统计数据
  getData() {
    let that = this;

    wx.$api.getHome().then(r => {
      if(r.data.code == 200){
        let {
          company_name,
          toady_cnt,
          week_cnt,
          mouth_cnt,
          legal_person
        } = r.data.data || {}
        this.setData({
          company_name: company_name,
          toady_cnt: toady_cnt,
          week_cnt: week_cnt,
          mouth_cnt: mouth_cnt,
          legal_person:legal_person
        })
        wx.setStorageSync('tansline_remark', r.data.data.tansline_remark)
      }
    })

    wx.$api.arriveRegionList().then(r => {
      if (r.data.code == 200) {
        wx.setStorageSync('line', r.data.data || [])
      }
    })

    wx.$api.getRegionList().then(r => {
      if (r.data.code == 200) {
        wx.setStorageSync('lineList', r.data.data.list || [])
      }
    })
    
    wx.$api.userInfo().then(r => {
      if (r.data.code == 200) {
        wx.setStorageSync('user_infos',  r.data.data || {})
        //如果快递企业的话，隐藏 运营管理
        // if(r.data.data.company_type && that.data.swiperList.length == 4){       //如果是快递企业的话，去掉运营管理
          console.log('index_company_type', r.data.data.company_type);
          // this.data.swiperList.splice(2,1);
          this.setData({
            swiperList: this.data.swiperList,
            company_type: r.data.data.company_type
          });
        // }
       
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    wx.showLoading({
      title: '加载中...',
      icon: "none"
    })
    // console.log(wx.getStorageSync('company_id'))
    if(wx.getStorageSync('company_id')){
      this.setData({
        show: wx.getStorageSync('company_id') ? true : false
      })
      this.getData();
      return;
    }
    let set_ = wx.setStorageSync,
      self = this;
    getApp().getOpenid((data) => {
      console.log(data,'获取openid')
      let {
        company_id,
        user_id,
        token,
        apply_status
      } = data || {}
      set_('user_id', user_id);
      set_('token', token);
      set_('company_id', company_id);
      set_('apply_status', apply_status) // 0：申请中、1：审核通过、2：审核不通过 3 未申请
      self.setData({
        show: company_id ? true : false
      })
      if(apply_status == 0){
        return wx.navigateTo({
          url: '/pages/review/review',
        })
      }
      if (!company_id) { // 否则-【登录、没有登录】
        wx.reLaunch({
          url: '/pages/login/login',
        })
      }else{
        this.setData({
          show: wx.getStorageSync('company_id') ? true : false
        })
        this.getData();      
      }

      self.getData();
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})